package au.com.handsunited.model.message;

import java.io.Serializable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import au.com.handsunited.model.BaseEntity;
import au.com.handsunited.model.MotherOfAllEntities;

/**
 *
 *
 * @author arunda
 */
public class Message extends MotherOfAllEntities implements Comparable<Message>, Serializable {

	private String text;
	private MessageBoard messageBoard;
	private BaseEntity poster;
	private MessageStatus status;

	private static Logger logger = LoggerFactory.getLogger(Message.class);


	/**
	 *
	 */
	public Message() {
		super();
		status = MessageStatus.UNREAD;
	}

	/**
	 *
	 * @param text
	 */
	public Message (String text, BaseEntity poster) {
		this();
		this.text = text;
		this.poster = poster;
	}

	/**
	 * @see au.com.handsunited.model.message.Message#getText()
	 */
	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public BaseEntity getPoster() {
		return poster;
	}

	public void setPoster(BaseEntity poster) {
		this.poster = poster;
	}

	public MessageStatus getStatus() {
		return status;
	}

	public void setStatus(MessageStatus status) {
		this.status = status;
	}

	public MessageBoard getMessageBoard() {
		return messageBoard;
	}

	public void setMessageBoard(MessageBoard messageBoard) {
		this.messageBoard = messageBoard;
	}

	public void markMessageAsRead() {
		setStatus(MessageStatus.READ);
	}

	public void markMessageAsUnread() {
		setStatus(MessageStatus.UNREAD);
	}

	public boolean isRead() {
		return status.compareTo(MessageStatus.READ) == 0;
	}

	public boolean isUnread() {
		return status.compareTo(MessageStatus.UNREAD) == 0;
	}

	public boolean isAwaitingApproval() {
		return status.compareTo(MessageStatus.AWAITING_APPROVAL) == 0;
	}

	public int compareTo(Message message) {
		return getDateCreated().compareTo(message.getDateCreated());
	}

}
